#include<iostream>
#include<poll.h>
#include<unistd.h>
int main(){
    struct pollfd rfds;
    rfds.fd = 0;
    rfds.events = POLLIN;
    rfds.revents = 0;

    while(1){
        int n = poll(&rfds, 1, 1000);
        switch (n){
        case 0:
            std::cout << "time out" << std::endl;
            break;
        case -1:
            std::cout << "poll error" << std::endl;
            break;
        default:
            std::cout << "有事件发生..." << std::endl;
            if(rfds.revents & POLLIN){
                std::cout << rfds.fd << "号文件描述符上面的读事件发生了" << std::endl;
                char buffer[128];
                ssize_t s = read(0, buffer, sizeof(buffer) - 1);
                if(s > 0){
                    std::cout << "有人说#" << buffer << std::endl;
                }
            }
            break;
        }
    }
    return 0;
}